﻿using System;
using System.Collections.Generic;
using Medart.Models;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Medart.Controllers
{
    public class ColorController : Controller
    {
        
        CalendarDataContext db = new CalendarDataContext();
        //
        // GET: /Color/

        public ActionResult Index()
        {
            
        var colors = from m in db.COLORs
        select m;
            return View(colors);
        }

        //
        // GET: /Color/Details/5

        public ActionResult Details(int id)
        {

            return View();
        }

        //
        // GET: /Color/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Color/Create

        [HttpPost]
        public ActionResult Create(String COLOR1, String LABEL)
        {
            try
            {
   
                    COLOR c = new COLOR();

                    c.COLOR1 = COLOR1;
                    c.LABEL = LABEL;
                   db.COLORs.InsertOnSubmit(c);
                   db.SubmitChanges();
       

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Color/Edit/5

        public ActionResult Edit(int id)
        {
            COLOR cc = db.COLORs.Where(c => c.ID == id).FirstOrDefault();
            return View(cc);
        }

        //
        // POST: /Color/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, String COLOR1, String LABEL)
        {
            try
            {

                COLOR cc = db.COLORs.Where(c => c.ID == id).FirstOrDefault();

                cc.COLOR1 = COLOR1;
                cc.LABEL = LABEL;
            
                db.SubmitChanges();


                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Color/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Color/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
